package yuan.datastructure.list;

public class LinkStack implements Stack {
	private List list;
	
	public LinkStack(){
		list = new LinkList();
	}
	
	@Override
	public void clear() {
		list.clear();
	}

	@Override
	public boolean isEmpty() {
		return list.isEmpty();
	}

	@Override
	public Object getTop() {
		if (!isEmpty())
			return list.first();
		
		return null;
	}

	@Override
	public void push(Object e) {
		list.insert(e, 0);
	}

	@Override
	public Object pop() {
		if (!isEmpty()){
			Object e = list.first();
			list.delete(0);
			return e;
		}
		
		return null;
			
	}

	@Override
	public int length() {
		return list.size();
	}

}
